Function: fig2image

CALL:

[image, bufferedimage] = fig2image(fig,insets)

DESCRIPTION:

Convert Matlab figure to java image.

INPUT:

fig figure
optional, handle of figure to convert to a java image
default value: gcf
insets number[4]
insets=[left bottom right top]
optional arguments, defaults to [0 0 0 0]

OUTPUT:

image java.awt.Image
bufferedimage java.awt.image.BufferedImage
An image with an accessible buffer with image data

EXAMPLE:

      hfig=figure;
      plot(1:10);
      [img, bimg] = fig2image(hfig);
      html = image2html(bimg, 'png');
      delete(hfig)
      disp(html)
 

APPROACH:

   print the figure to a temporary .png file using Matlab's print method
   get bufferedimage with javax.imageio.ImageIO and make an image from the
   bufferedimage with java.awt.Toolkit.
 
    Copyright 2006-2019 Modelit, www.modelit.nl